//
//  UIBarButtonItem+HL.m


#import "UIBarButtonItem+HL.h"

@implementation UIBarButtonItem (HL)

+ (UIBarButtonItem *)itemWithIconName:(NSString *)iconName hightIconName:(NSString *)hightIconName target:(id)target action:(SEL)action
{
    
    UIButton *button = [[UIButton alloc] init];
    [button setBackgroundImage:[UIImage imageNamed:iconName] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:hightIconName] forState:UIControlStateHighlighted];
    //leftBtn.bounds = CGRectMake(0, 0, leftBtn.currentBackgroundImage.size.width, leftBtn.currentBackgroundImage.size.height);
    button.bounds = (CGRect){CGPointZero,button.currentBackgroundImage.size};
    //监听按钮的点击
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc] initWithCustomView:button];

}

+ (UIBarButtonItem *)itemWithImage:(UIImage *)image highImage:(UIImage *)highImage target:(id)target action:(SEL)action title:(NSString *)title
{
    // 设置返回按钮
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setTitle:title forState:UIControlStateNormal];
    [backButton setImage:image forState:UIControlStateNormal];
    [backButton setImage:highImage forState:UIControlStateHighlighted];
    [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [backButton.titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
    [backButton sizeToFit];
    // 设置内容内边距
    backButton.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    
    UIView *contentView = [[UIView alloc] initWithFrame:backButton.bounds];
    [contentView addSubview:backButton];
    return  [[UIBarButtonItem alloc] initWithCustomView:contentView];
    
}

@end
